home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13222 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  88 lines

  1. Path: news.compuserve.com!newsmaster
  2. From: 101513.2141@compuserve.com (Jean-Marc Delforge)
  3. Newsgroups: comp.unix.programmer,comp.lang.c
  4. Subject: Re: Applying file masks in UNIX using C/C++
  5. Date: Fri, 05 Apr 1996 09:33:54 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4k2lub$9oe@dub-news-svc-1.compuserve.com>
  8. References: <31618AFE.5476@netrover.com>
  9. NNTP-Posting-Host: hd42-154.compuserve.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Stephane Charette <charrick@netrover.com> wrote:
  13.  
  14. >This is a long shot...but...does anyone know of the existence
  15. >of public domain C/C++ code which will apply a file mask to
  16. >an existing filename and return a TRUE or FALSE response?
  17.  
  18. >For example:  if I have a mask of "a??01.text.*" and I have
  19. >the files "abc01.text.old", "az01.text.new" and "az01.text",
  20. >then it would return positive on the first two, but negative
  21. >on the last.  Does this make sense?
  22.  
  23. >What I hope, is that someone has already done all of this and
  24. >put it up there on an FTP site.  Thing is, I can't find it...
  25. >WWW searches have turned up nothing so far either.  (The fact
  26. >that I have no idea what this would be called doesn't help.)
  27.  
  28. >Thanks for your help,
  29.  
  30. >Stephane Charette
  31.  
  32. Try This.
  33. This is working like UNIX wildcards.
  34. More best than DOS wildcards.
  35. It's comminig from my mind. 
  36. It's working recusrively, and for strings of any size. 
  37.  
  38. /*
  39. ** str_filter.c
  40. ** (c) smals 1992
  41. ** Delforge jm 2641
  42. */
  43.  
  44. #include <dos.h>
  45.  
  46. int StrFilter (char * str, char * mask)
  47. {
  48.     char * pm, *ps;
  49.  
  50.     pm = mask;
  51.     ps = str;
  52.  
  53.     if (*pm == 0) return (1);
  54.  
  55.     while (*pm != 0)
  56.     {
  57.         switch (*pm)
  58.         {
  59.             case '*' : 
  60.                 pm++;
  61.                 if (*ps == 0) return (1);
  62.                 while (*ps != 0)
  63.                 {
  64.                     if (StrFilter (ps, pm)) return (1);
  65.                     ps++;
  66.                 }
  67.                 return (0);
  68.             case '?' :
  69.                 if (*ps == 0) return (0);
  70.                 ps++; pm++;
  71.                 break;
  72.             default :
  73.                 if (*pm != *ps) return (0);
  74.                 pm++, ps++;
  75.                 break;
  76.         }
  77.     }
  78.     if (*ps == 0) return (1);
  79.     else return (0);
  80. }
  81.  
  82. /* eof */
  83.  
  84. Jean-Marc Delforge
  85. Smals - Belgium - Brussels
  86. 101513.2141@compuserve.com
  87.  
  88.